<?php
// 产品列表

$sys = fn_configura($this->website, 'sys');
$json = array('status' => 'error', 'msg' => '', 'data' => false);

$tid = fn_post('tid');
$self = explode(',', $sys['selfid']);

if (!$tid) {
	$json['msg'] = "获取数据错误,请重新选择";
} else {
	$json['status'] = 'ok';

	$json['data'] = $this->website['class']['db']
		->table("product")
		->where("tid=? and checked=1", $tid)
		->num($sys['pagingnum'] ?? 20)
		->paging();
	foreach ($json['data']['data'] as &$v) {
		$v['image'] = fn_image($this->website, $v['image']);
		$v['shops'] = $this->website['class']['db']
			->table('shops')
			->where('id=?', $v['uid'])
			->one();
		$v['self'] = in_array($v['uid'], $self);
	}
	// $order = [];
	// if ($credit) {$order[] = 'credit desc';}
	// if ($sales) {$order[] = 'sales desc';}
	// if ($price) {$order[] = 'price desc';}
	// if (count($order)) {
	// 	$this->website['class']['db']
	// 		->order(implode(',', $order));
	// }
}

// $json['sql'] = $this->website['class']['db']->sql;

$this->json_encode_encrypt($json);